package com.power.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.power.domain.Notice;
import com.power.mapper.NoticeMapper;
import com.power.service.NoticeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {
    @Autowired
    private NoticeMapper mapper;
    @Override
    public Page getNoticePage(Page<Notice> page, String title, Integer status, Integer isTop) {
        Page<Notice> page1 = mapper.selectPage(page, new LambdaQueryWrapper<Notice>().like(StringUtils.isNotEmpty(title), Notice::getTitle, title)
                .eq(status != null, Notice::getStatus, status)
                .eq(isTop != null, Notice::getIsTop, isTop));
        return page1;

    }

    @Override
    public boolean addNotice(Notice notice) {
        return mapper.insert(notice)>0;
    }

    @Override
    public boolean DeleteById(Long id) {
        Boolean status = mapper.selectById(id).getStatus();
        if (mapper.selectById(id).getStatus()) {
            return false;
        }
        return mapper.deleteById(id)>0;
    }
}



